package edu.hawaii.myisern.model;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test; 

/**
 * Test User model instance.
 * 
 * @author Lisa Chen
 */
public class TestUser {

  /**
   * Tests all public operations of model User class.
   * 
   * @throws Exception If problems occur during test.
   */
  @Test
  public void testUserModel() throws Exception {
    String testUsername = "testUser";
    String testPassword = "testPass";
    User testUser = new User(testUsername, testPassword);
    
    testUser.setUsername(testUsername);
    testUser.setPassword(testPassword);
    
    assertEquals("Check getUsername is the same as testUsername.", 
        testUser.getUsername(), testUsername);
    assertEquals("Check getPassword is the same as testPassword.", 
        testUser.getPassword(), testPassword);
    assertTrue("Check overriden equals method works.", 
        testUser.getUsername().equals(testUsername));
    
    Integer testId = 7;
    testUser.setId(testId);
    
    assertEquals("Check getId is the same as testId.", 
        testUser.getId(), testId);
    
    int testHash = testUser.hashCode();
    assertEquals("Check overriden hashCode method works.", 
        testUser.hashCode(), testHash);

    User testUser2 = new User(testUsername, testPassword);
    testUser2.setId(8);
    assertFalse("2 Users should be different.", testUser2.equals(testUser));
    testUser2.setId(7);
    assertEquals("2 Users should be equal.", testUser2, testUser);
  }
}
